package com.tte.common.anno.DictConver;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * 拦截所有SQL,对实体分类中配置相应注解的字段（DictConver）进行字典转换
 */
@Slf4j
@Aspect
@Component
public class DictAspect {

    ////指定mapper下所有查询方法
//    @Pointcut("execution(* com.*.*.mapper.*.*(..))")
//    public void doPointcut() {
//    }


    @Pointcut("@annotation(com.tte.common.anno.DictConver.DictConvertForMethod)")
    public void doPointcut() {
    }


    @AfterReturning(pointcut = "doPointcut()", returning = "result")
    public void doAfterReturning(JoinPoint pjp, Object result) {
        try {
            DictUtils.convertDict(result);
        } catch (Exception e) {
            log.error("查询结果字典转换失败", e);
        }
    }

}
